package com.xcdh.trading.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.trading.entity.SectorCapitalFlow;
import com.xcdh.trading.entity.ZtStock;
import com.xcdh.trading.mapper.ZtStockMapper;
import com.xcdh.trading.response.TradingRes;
import com.xcdh.trading.service.ZtStockService;
import com.xcdh.trading.util.TuShareApi;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 涨停股票信息服务实现类，继承 ServiceImpl 实现具体业务逻辑
 */
@Service
public class ZtStockServiceImpl extends ServiceImpl<ZtStockMapper, ZtStock> implements ZtStockService {
    @Override
    public void syncZtStock(String tradeDate) {
        TradingRes tradingRes = TuShareApi.post("limit_list_d", tradeDate);
        List<ZtStock> stockList = tradingRes.parse(ZtStock.class);
        for (ZtStock stock : stockList) {
            ZtStock ztStock = lambdaQuery()
                    .eq(ZtStock::getTsCode, stock.getTsCode())
                    .eq(ZtStock::getTradeDate, stock.getTradeDate()).one();
            if(ztStock == null){
                save(stock) ;
            }
        }
    }
}

